package cn.bdqn.sys.controller;

import cn.bdqn.annotation.SysLog;
import cn.bdqn.model.PageBean;
import cn.bdqn.sys.model.User;
import cn.bdqn.sys.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Awacky
 * @create 2019-07-27 12:24
 */
@Controller
@RequestMapping("/sys/user")
public class UserController {
    //调用
    @Autowired
    private UserService userService;

    @RequiresPermissions("sys:user:page")
    @GetMapping
    public String topage(){
        return "/sys/user";
    }

    //测试，前台给后台传值
    @SysLog("用户登录")
    @ResponseBody
    @PostMapping("/login")
    public Object login(String username, String password, String imageCode){
        return userService.login(username,password,imageCode);
    }
    @RequiresPermissions("sys:user:updatepassword")
    @ResponseBody
    @PostMapping("/updatepassword")
    public Object updatepassword(String oldpassword, String newPassword1, String newPassword2){
        return userService.update(oldpassword,newPassword1,newPassword2);
    }

    @RequiresPermissions("sys:user:list")
    @PostMapping("list")
    @ResponseBody
    public Object list(PageBean pageBean, String username, Boolean sex){
        return userService.list(pageBean, username, sex);
    }

    @RequiresPermissions("sys:user:save")
    @PostMapping("/save")
    @ResponseBody
    public Object save(User user){
        return userService.save(user);
    }

    @RequiresPermissions("sys:user:delete")
    @PostMapping("delete")
    @ResponseBody
    public Object delete(Integer userid){
        return userService.delete(userid);
    }

    @RequiresPermissions("sys:user:setrole")
    @PostMapping("setrole")
    @ResponseBody
    public Object setrole(Integer userid, String roleids, String roleNames){
        return userService.setrole(userid, roleids, roleNames);
    }
}
